package br.ufpi.hu.prescricao.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name = "roles", schema = "autenticacao")
@SequenceGenerator(name="roles_seq", sequenceName="autenticacao.roles_seq", initialValue=1, allocationSize=1)
public class Role {

	@Id
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="roles_seq")
	private int id;
	
	@Column(nullable = false)
	private String role;
	
	@Column(nullable = false)
	private String rolegroup;
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "usuario_id", nullable = false)
	private Usuario usuario;
	
	public Role(String role, String rolegroup) {
		this.role = role;
		this.rolegroup = rolegroup;
		 
	}
	
	public Role() {}

	public Usuario getUsuario() {
		return this.usuario;
	}
	
	public void setUsuario(Usuario usuario) {
		this.usuario = usuario;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getRole() {
		return role;
	}

	public void setRole(String role) {
		this.role = role;
	}

	public String getRolegroup() {
		return rolegroup;
	}

	public void setRolegroup(String rolegroup) {
		this.rolegroup = rolegroup;
	}

	@Override
	public int hashCode() {
		return getId();
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj instanceof Role){
			Role user = (Role) obj;
			return user.getId()==(getId());
		}
		
		return false;
	}

}
